var appInfoId = GetQueryString("appInfoId");
console.log(appInfoId);

function closeWin() {
    window.opener=null;
    window.open('','_self');
    window.close();
}


var vm = new Vue({
    el:"#showDetail",
    data:{
        q: {
            type: '',
            state: '',
            address: '',
            userName: ''
        },
        typeObject:{}, //类型集合
        stateObject:{}, //状态集合
        plateNumberAreaObject:{},//车牌地区集合 e.g. 鲁A
        illegalTypeObject:{},//违法类型集合
        vehicleTypeObject:{},//车辆类型集合
        showList: true,
        title: '查看详情',
        appInfo: {}
    },
    mounted:function(){
        this.$nextTick(function(){
            this.getInfo(appInfoId)
        });
    },
    methods:{
        getInfo: function(id){
            $.get(baseURL + "appReport/appinfo/info/"+id, function(r){
                vm.appInfo = r.appInfo;
                console.log(JSON.stringify(vm.appInfo))
                console.log(JSON.stringify(vm.appInfo))
                console.log(JSON.stringify(vm.appInfo))
                console.log(JSON.stringify(vm.appInfo))
                console.log(JSON.stringify(vm.appInfo))
            });
            $.get(baseURL + "sys/dict/select/illegalType", function (r) {
                if (r.code === 0) {
                    vm.illegalTypeObject = r.dict;
                } else {
                    console.log(r.msg);
                }
            });
            $.get(baseURL + "sys/dict/select/vehicleType", function (r) {
                if (r.code === 0) {
                    vm.vehicleTypeObject = r.dict;
                } else {
                    console.log(r.msg);
                }
            });
            $.get(baseURL + "sys/dict/select/plateNumberArea", function (r) {
                if (r.code === 0) {
                    vm.plateNumberAreaObject = r.dict;
                } else {
                    console.log(r.msg);
                }
            });
        },
        update: function(){
            var _this = this;
            _this.appInfo.appInfoId = appInfoId;
            $.ajax({
               type: 'POST',
               url: baseURL + "appReport/appinfo/update",
               contentType: "application/json",
               data: JSON.stringify(_this.appInfo),
                success: function(response){
                   if(response.code === 0){
                       alert('操作成功',function(index){
                           var url = baseURL + "ehualu-admin/modules/appReport/appinfoCheck.html?sessionid=73ba6e1d-a726-4af0-b405-e727acdb0c33" ;
                           window.location.href = url;
                           closeWin();
                           /*var url = baseURL + "ehualu-admin/modules/appReport/appinfoCheck.html" ;
                           var sWinName = "LR"+parseInt(Math.random() * 100000000);//利用随机数处理WinName
                           window.open(url,sWinName, 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=yes,copyhistory=yes');
                           */
                           // _this.$router.push({path:'/appinfoCheck.html'})
                       });
                   }else {
                       alert(response.msg);
                   }
                }
            });
        },
        getVehicleInfo: function(){
            var _this = this;
            _this.appInfo.appInfoId = appInfoId;
            console.log(_this.appInfo);
            console.log(_this.appInfo);
            var vehicleType = _this.appInfo.vehicleType;
            if (vehicleType == undefined || vehicleType == null || vehicleType  == ""){
                alert('请选择车辆类型');
                return false;
            }
            var illegalPlateNumber = _this.appInfo.illegalPlateNumber;
            if (illegalPlateNumber === undefined || illegalPlateNumber === null || illegalPlateNumber.length === 0){
                alert('请输入号牌号码');
                return false;
            }
            $.ajax({
                type: 'POST',
                url: baseURL + "appReport/appinfo/info1",
                contentType: "application/json",
                data: JSON.stringify(_this.appInfo),
                success: function(response){
                    console.log(response);
                    if (response.code === 0 ){
                        // 根据违法号牌种类判断是否查询到了数据
                       var illegalPlateType =  response.appInfo.illegalPlateType;
                        if(illegalPlateType === undefined || illegalPlateType === null || illegalPlateType.length === 0){
                            alert('未查询违法车辆信息，请重试');
                            _this.appInfo = response.appInfo;
                            return;
                        }
                        _this.appInfo = response.appInfo;
                        alert('数据获取成功');

                    }
                    else{
                        alert(response.msg);
                    }
                }
            });
        },
       /* reload: function (event) {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                postData: {
                    'type': vm.q.type,
                    'state': vm.q.state,
                    'address': vm.q.address,
                    'userid': vm.q.userid
                },
                page: page
            }).trigger("reloadGrid");
        }*/
    }
});

//上报状态字典
function stateFormate(value, options, row) {
    //sex为自定义字典项
    var statusObj = vm.stateObject.reportState;
    console.log(JSON.stringify(statusObj));
    for (var i = 0; i < statusObj.length; i++) {
        if (statusObj[i].value == value) {
            return '<span>' + statusObj[i].text + '</span>';
        }
    }
}
